﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace web.Pages.xml
{
    public partial class diseaselist_xml : System.Web.UI.Page
    {
        protected List<DiseaseInfo> DiseaseDataList;
        protected int DiseaseCount = 105;
        protected int DiseasePageCount;
        protected int DiseasePageSize = 7;
        protected int DiseasePageIndex = 1;
        

        protected void HandleGet()
        {
           
            DiseasePageIndex = RequestTools.GetFormInt("pno", 1);
            DiseasePageSize = RequestTools.GetFormInt("pnum", 7);
            DiseaseSearchCondtion cond = new DiseaseSearchCondtion();
            cond.FirstLetter = RequestTools.GetFormString("firstLetter");

            DiseaseDataList = new List<DiseaseInfo>();

            DiseaseDataList = DiseaseBLL.Instance.GetDiseaseList(
               DiseasePageSize, DiseasePageIndex,
               cond, out DiseaseCount);

            //生产xml文档
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = ("    ");
            Response.ContentType = "text/xml";
            using (XmlWriter wr = XmlWriter.Create(Response.OutputStream, settings))
            {
                // Write XML data.
                wr.WriteStartElement("result");
                wr.WriteAttributeString("code", "0");
                wr.WriteStartElement("diseases");
                wr.WriteAttributeString("count", DiseaseCount.ToString());
                foreach (DiseaseInfo info in DiseaseDataList)
                {
                    wr.WriteStartElement("disease");
                    wr.WriteAttributeString("id", info.Id.ToString());
                    wr.WriteAttributeString("name", info.Name.ToString());
                    wr.WriteAttributeString("desc", info.Intro);
                    wr.WriteAttributeString("count", info.PatientCount.ToString());
                    wr.WriteEndElement();
                }


                wr.WriteEndElement();
                wr.WriteEndElement();
                wr.Flush();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HandleGet();
        }
    }
}
